﻿using UtfprLibrary.Windows.Forms;
using System.Linq;
using System.Windows.Forms;
using WinFormApp_Sample.Data;
using UtfprLibrary.Windows.Forms.ComponentModel;

namespace WinFormApp_Sample.WinForm {
    public sealed partial class FormFooRequiredCrud : UtfprFormCrudBase {
        private readonly UBNValidatableControlCollection validatableA;
        private readonly UBNValidatableControlCollection validatableB; 

        public FormFooRequiredCrud() {
            InitializeComponent();
            validatableA = new UBNValidatableControlCollection();
            validatableA.Add(_reqEstado.ValidatableControlCollection.OfType<UtfprValidatableControl>().Single(c => c.Control == _gbxEstadoA));
            validatableB = new UBNValidatableControlCollection();
            validatableB.Add(_reqEstado.ValidatableControlCollection.OfType<UtfprValidatableControl>().Single(c => c.Control == _gbxEstadoB));
        }

        private void _btnValidate_Click(object sender, System.EventArgs e) {
            _reqEstado.CancelValidation();
            _reqEstado.Validate();
        }

        private void _btnB_Click(object sender, System.EventArgs e) {
            _reqEstado.ValidatableControlCollection.Clear();
            foreach (UtfprValidatableControl b in validatableB) {
                _reqEstado.ValidatableControlCollection.Add(b);
            }
        }

        private void _btnA_Click(object sender, System.EventArgs e) {
            _reqEstado.ValidatableControlCollection.Clear();
            foreach (UtfprValidatableControl a in validatableA) {
                _reqEstado.ValidatableControlCollection.Add(a);
            }
        }

        private void _btnInit_Click(object sender, System.EventArgs e) {
            _gbxEstadoB.Enabled = true;
            _gbxEstadoA.Enabled = true;
            _radEstadoB1.Enabled = true;
            _radEstadoB2.Enabled = true;
            _radEstadoA1.Enabled = true;
            _radEstadoA2.Enabled = true;
            _radEstadoB1.Checked = false;
            _radEstadoA1.Checked = false;
        }
    }
}